{{- define "resources_argocd-applicationset-controller" }}
cpu: 50m
memory: 100Mi
{{- end }}

{{- if (.Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
---
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: argocd-applicationset-controller
  namespace: d8-{{ .Chart.Name }}
  {{- include "helm_lib_module_labels" (list . (dict "app" "argocd-applicationset-controller")) | nindent 2 }}
spec:
  targetRef:
    apiVersion: "apps/v1"
    kind: Deployment
    name: argocd-applicationset-controller
  updatePolicy:
    updateMode: "Auto"
  resourcePolicy:
    containerPolicies:
    - containerName: argocd-applicationset-controller
      minAllowed:
        {{- include "resources_argocd-applicationset-controller" . | nindent 8 }}
      maxAllowed:
        cpu: 100m
        memory: 200Mi
{{- end }}
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: argocd-applicationset-controller
  namespace: d8-{{ .Chart.Name }}
  {{- include "helm_lib_module_labels" (list . (dict "app.kubernetes.io/name" "argocd-applicationset-controller" "app" "argocd-applicationset-controller")) | nindent 2 }}
spec:
  maxUnavailable: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: argocd-applicationset-controller
---
apiVersion: apps/v1
kind: Deployment
metadata:
  {{- include "helm_lib_module_labels" (list . (dict "app.kubernetes.io/component" "controller" "app.kubernetes.io/name" "argocd-applicationset-controller" "app.kubernetes.io/part-of" "argocd-applicationset" "app" "argocd-applicationset-controller")) | nindent 2 }}
  name: argocd-applicationset-controller
  namespace: d8-{{ .Chart.Name }}
spec:
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app.kubernetes.io/name: argocd-applicationset-controller
  template:
    metadata:
      labels:
        app.kubernetes.io/name: argocd-applicationset-controller
        app: argocd-applicationset-controller
    spec:
      {{- include "helm_lib_node_selector" (tuple . "system") | nindent 6 }}
      {{- include "helm_lib_tolerations" (tuple . "system") | nindent 6 }}
      {{- include "helm_lib_priority_class" (tuple . "cluster-medium") | nindent 6 }}
      {{- include "helm_lib_pod_anti_affinity_for_ha" (list . (dict "app" .Chart.Name)) | nindent 6 }}
      {{- include "helm_lib_module_pod_security_context_run_as_user_nobody" . | nindent 6 }}
      containers:
        - command:
            - entrypoint.sh
            - argocd-applicationset-controller
          env:
            - name: NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          image: {{ include "helm_lib_module_image" (list . "argocd") }}
          imagePullPolicy: IfNotPresent
          name: argocd-applicationset-controller
          ports:
            - containerPort: 7000
              name: webhook
            - containerPort: 8080
              name: metrics
          {{- include "helm_lib_module_container_security_context_read_only_root_filesystem_capabilities_drop_all" . | nindent 10 }}
          resources:
            requests:
              {{- include "helm_lib_module_ephemeral_storage_logs_with_extra" 1024 | nindent 14 }}
{{- if not ( .Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
              {{- include "resources_argocd-applicationset-controller" . | nindent 14 }}
{{- end }}
          volumeMounts:
            - mountPath: /app/config/ssh
              name: ssh-known-hosts
            - mountPath: /app/config/tls
              name: tls-certs
            - mountPath: /app/config/gpg/source
              name: gpg-keys
            - mountPath: /app/config/gpg/keys
              name: gpg-keyring
            - mountPath: /tmp
              name: tmp
      serviceAccountName: argocd-applicationset-controller
      volumes:
        - configMap:
            name: argocd-ssh-known-hosts-cm
          name: ssh-known-hosts
        - configMap:
            name: argocd-tls-certs-cm
          name: tls-certs
        - configMap:
            name: argocd-gpg-keys-cm
          name: gpg-keys
        - emptyDir: {}
          name: gpg-keyring
        - emptyDir: {}
          name: tmp
